var pomelo = require('pomelo');
var bearcat = require("bearcat")
var areaFilter = require('./util/filters/areaFilter.js');
var contextPath = require.resolve('./context.json');
bearcat.createApp([contextPath],{ BEARCAT_HOT: "off"})
/**
 * Init app for client.
 */
var app = pomelo.createApp();
app.set('name', 'hainanribao');
bearcat.start(function() {
  app.configure('production|development', 'connector', function(){
    app.set('connectorConfig',
      {
        connector : pomelo.connectors.hybridconnector,
        heartbeat : 3,
        useDict : true,
        useProtobuf : true,
        // ssl: {
        //   type: 'wss',
        //   key: fs.readFileSync('./keys/yechenggame.key'),
        //   cert: fs.readFileSync('./keys/yechenggame.pem'),
        // }
      });
      app.filter(pomelo.filters.serial());
      //检测到node.js中事件循环的请求等待队列过长，超过一个阀值时，就会触发toobusy
      app.before(pomelo.filters.toobusy());
      //处理超时进行警告，默认三秒
      app.filter(pomelo.filters.timeout());
      setInterval(()=>{
          let s = app.components.__connection__;
          console.log("loginedCount:",s.getStatisticsInfo().loginedCount);
      }, 30000);
  });
  // start app
  app.start(function() {
    app.configure('production|development', 'area', function() {
      app.before(areaFilter());
      var area = bearcat.getBean("area",app)
      app.set("area",area)
    });
  })
})

process.on('uncaughtException', function (err) {
  console.error(' Caught exception: ' + err.stack);
});
